



// This code is a generated code by a tool
// designed and coded by Shohdi Mohamed Elsheemy ( shohdi@gmail.com )            

using System;
using System.Collections.Generic;
using System.Web;
using System.Data.Common;
using Shohdi.DataHandler;
using System.Data;




namespace DatabaseComponent
{
    
    public partial class MaxVisitsDateDB
    {
         string _Connection = "";


        public string Connection
        {
            get { return _Connection; }
            set { _Connection = value; }
        }


       
         string _Provider = "System.Data.SqlClient";

        
        public string Provider
        {
            get { return _Provider; }
            set { _Provider = value; }
        }



        public MaxVisitsDateDB()
        {
        }

        public MaxVisitsDateDB(string __Connection,params string [] __Provider)
        {

            if (__Provider.Length > 0)
                _Provider = __Provider[0];

            _Connection = __Connection;
            
        }




        public List<MaxVisitsDate> Select(ClassDataHandler con, string strTop, string strWhere, params DbParameter[] whereParams)
        {
            if (whereParams == null)
                whereParams = new DbParameter[0];

            List<MaxVisitsDate> lstRet = new List<MaxVisitsDate>();

            string strQuery = " select " + strTop  + " * from dbo.[MaxVisitsDate]  " ;

            if (strWhere != "")
            {
                strQuery = strQuery + "  " + strWhere;
            }

            DbDataReader dr = con.SelectDataReader(strQuery, CommandType.Text, whereParams);


            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    MaxVisitsDate obj = new MaxVisitsDate();
 if (dr["ID"] != DBNull.Value)
                    {
                        obj.ID = (System.Int64)dr["ID"];
                    }
                    else
                    {
                        obj.ID = -1;
                    } 
 if (dr["MaxConcurrenceNumber"] != DBNull.Value)
                    {
                        obj.MaxConcurrenceNumber = (System.Int64)dr["MaxConcurrenceNumber"];
                    }
                    else
                    {
                        obj.MaxConcurrenceNumber = -1;
                    } 
 if (dr["CurrentDate"] != DBNull.Value)
                    {
                        obj.CurrentDate = (System.DateTime)dr["CurrentDate"];
                    }
                    else
                    {
                        obj.CurrentDate = DateTime.Now;
                    } 



                    lstRet.Add(obj);
                   

                }
            }

            dr.Close();


            return lstRet;
        }


        public List<MaxVisitsDate> Select(string strTop, string strWhere, params DbParameter[] whereParams)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<MaxVisitsDate> lstRet = Select(con, strTop, strWhere, whereParams);

            con.CloseConnection();

            return lstRet;
        }

        



        public void Insert(ClassDataHandler con , MaxVisitsDate obj)
        {
            
            

                    DbParameter prmMaxConcurrenceNumber = con.createParameter();
                    prmMaxConcurrenceNumber.ParameterName = "@MaxConcurrenceNumber";
                    prmMaxConcurrenceNumber.DbType =DbType.Int64;
                    if (obj.MaxConcurrenceNumber == null)
                    {
                        prmMaxConcurrenceNumber.Value = DBNull.Value;
                    }
                    else
                    {
                        prmMaxConcurrenceNumber.Value = obj.MaxConcurrenceNumber;
                    }
                

                    


                    DbParameter prmCurrentDate = con.createParameter();
                    prmCurrentDate.ParameterName = "@CurrentDate";
                    prmCurrentDate.DbType =DbType.DateTime;
                    if (obj.CurrentDate == null)
                    {
                        prmCurrentDate.Value = DBNull.Value;
                    }
                    else
                    {
                        prmCurrentDate.Value = obj.CurrentDate;
                    }
                

                    


           



            string strQuery = " insert into dbo.[MaxVisitsDate] ([MaxConcurrenceNumber],[CurrentDate]) VALUES (@MaxConcurrenceNumber,@CurrentDate) ; select SCOPE_IDENTITY() ";
 object scope = con.ExecuteScalar(strQuery, CommandType.Text, prmMaxConcurrenceNumber,prmCurrentDate);


                    try
                    {
                        obj.ID = System.Int64.Parse(scope.ToString());
                    }
                    catch
                    {
                        obj.ID = -1;
                    }


                    


           

        }



        public void Insert(MaxVisitsDate obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Insert(con,obj);


            con.CloseConnection();
        }




        public void Update(ClassDataHandler con, MaxVisitsDate obj)
        {
            
            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


                    DbParameter prmMaxConcurrenceNumber = con.createParameter();
                    prmMaxConcurrenceNumber.ParameterName = "@MaxConcurrenceNumber";
                    prmMaxConcurrenceNumber.DbType =DbType.Int64;
                    if (obj.MaxConcurrenceNumber == null)
                    {
                        prmMaxConcurrenceNumber.Value = DBNull.Value;
                    }
                    else
                    {
                        prmMaxConcurrenceNumber.Value = obj.MaxConcurrenceNumber;
                    }
                

                    


                    DbParameter prmCurrentDate = con.createParameter();
                    prmCurrentDate.ParameterName = "@CurrentDate";
                    prmCurrentDate.DbType =DbType.DateTime;
                    if (obj.CurrentDate == null)
                    {
                        prmCurrentDate.Value = DBNull.Value;
                    }
                    else
                    {
                        prmCurrentDate.Value = obj.CurrentDate;
                    }
                

                    


           



            string strQuery = " update dbo.[MaxVisitsDate] set [MaxConcurrenceNumber]=@MaxConcurrenceNumber,[CurrentDate]=@CurrentDate where  [ID]=@ID  ";

            con.ExecuteNonQuery(strQuery, CommandType.Text,prmID,prmMaxConcurrenceNumber,prmCurrentDate);

            

        }


        public void Update(MaxVisitsDate obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Update(con, obj);


            con.CloseConnection();
        }



        public void Delete(ClassDataHandler con, MaxVisitsDate obj)
        {

            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


           



           



            string strQuery = " delete from dbo.[MaxVisitsDate]  where  [ID]=@ID  "; 
                        con.ExecuteNonQuery(strQuery, CommandType.Text,prmID );  

             



        }


        public void Delete( MaxVisitsDate obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            Delete(con, obj);

            con.CloseConnection();
        }





                    public List<MaxVisitsDate> getMaxVisitsDateByID(ClassDataHandler con,System.Int64 ID)
                    {
                        List<MaxVisitsDate> lstRet = new List<MaxVisitsDate>();


                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType = DbType.Int64;
                        if (ID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmID.Value = ID;
                        }


                        lstRet = Select(con, "" , " where [ID]=@ID ", prmID);



                        return lstRet;

                    }


                    public List<MaxVisitsDate> getMaxVisitsDateByID(System.Int64 ID)
                    {
                        List<MaxVisitsDate> lstRet = new List<MaxVisitsDate>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getMaxVisitsDateByID(con, ID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<MaxVisitsDate> getMaxVisitsDateByMaxConcurrenceNumber(ClassDataHandler con,System.Int64 MaxConcurrenceNumber)
                    {
                        List<MaxVisitsDate> lstRet = new List<MaxVisitsDate>();


                        DbParameter prmMaxConcurrenceNumber = con.createParameter();
                        prmMaxConcurrenceNumber.ParameterName = "@MaxConcurrenceNumber";
                        prmMaxConcurrenceNumber.DbType = DbType.Int64;
                        if (MaxConcurrenceNumber == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmMaxConcurrenceNumber.Value = MaxConcurrenceNumber;
                        }


                        lstRet = Select(con, "" , " where [MaxConcurrenceNumber]=@MaxConcurrenceNumber ", prmMaxConcurrenceNumber);



                        return lstRet;

                    }


                    public List<MaxVisitsDate> getMaxVisitsDateByMaxConcurrenceNumber(System.Int64 MaxConcurrenceNumber)
                    {
                        List<MaxVisitsDate> lstRet = new List<MaxVisitsDate>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getMaxVisitsDateByMaxConcurrenceNumber(con, MaxConcurrenceNumber);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<MaxVisitsDate> getMaxVisitsDateByCurrentDate(ClassDataHandler con,System.DateTime CurrentDate)
                    {
                        List<MaxVisitsDate> lstRet = new List<MaxVisitsDate>();


                        DbParameter prmCurrentDate = con.createParameter();
                        prmCurrentDate.ParameterName = "@CurrentDate";
                        prmCurrentDate.DbType = DbType.DateTime;
                        if (CurrentDate == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmCurrentDate.Value = CurrentDate;
                        }


                        lstRet = Select(con, "" , " where [CurrentDate]=@CurrentDate ", prmCurrentDate);



                        return lstRet;

                    }


                    public List<MaxVisitsDate> getMaxVisitsDateByCurrentDate(System.DateTime CurrentDate)
                    {
                        List<MaxVisitsDate> lstRet = new List<MaxVisitsDate>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getMaxVisitsDateByCurrentDate(con, CurrentDate);

                        con.CloseConnection();

                        return lstRet;

                    }



                

            
public List<MaxVisitsDate> Search(ClassDataHandler con, MaxVisitsDate obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID AND ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.MaxConcurrenceNumber != -1)
                    {
                        DbParameter prmMaxConcurrenceNumber = con.createParameter();
                        prmMaxConcurrenceNumber.ParameterName = "@MaxConcurrenceNumber";
                        prmMaxConcurrenceNumber.DbType =DbType.Int64;
                        if (obj.MaxConcurrenceNumber == null)
                        {
                            prmMaxConcurrenceNumber.Value = DBNull.Value;
                        }
                        else
                        {
                            prmMaxConcurrenceNumber.Value = obj.MaxConcurrenceNumber;
                        }
                        strWhere += " [MaxConcurrenceNumber]=@MaxConcurrenceNumber AND ";
                        lstParameters.Add(prmMaxConcurrenceNumber);
                     }



                    

                    if (obj.CurrentDate != DateTime.Now)
                    {
                        DbParameter prmCurrentDate = con.createParameter();
                        prmCurrentDate.ParameterName = "@CurrentDate";
                        prmCurrentDate.DbType =DbType.DateTime;
                        if (obj.CurrentDate == null)
                        {
                            prmCurrentDate.Value = DBNull.Value;
                        }
                        else
                        {
                            prmCurrentDate.Value = obj.CurrentDate;
                        }
                        strWhere += " [CurrentDate]=@CurrentDate AND ";
                        lstParameters.Add(prmCurrentDate);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("AND"));

                    

            

            List<MaxVisitsDate> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<MaxVisitsDate> Search(MaxVisitsDate obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<MaxVisitsDate> lstRet = Search(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                

            
public List<MaxVisitsDate> SearchOrLike(ClassDataHandler con, MaxVisitsDate obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID OR ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.MaxConcurrenceNumber != -1)
                    {
                        DbParameter prmMaxConcurrenceNumber = con.createParameter();
                        prmMaxConcurrenceNumber.ParameterName = "@MaxConcurrenceNumber";
                        prmMaxConcurrenceNumber.DbType =DbType.Int64;
                        if (obj.MaxConcurrenceNumber == null)
                        {
                            prmMaxConcurrenceNumber.Value = DBNull.Value;
                        }
                        else
                        {
                            prmMaxConcurrenceNumber.Value = obj.MaxConcurrenceNumber;
                        }
                        strWhere += " [MaxConcurrenceNumber]=@MaxConcurrenceNumber OR ";
                        lstParameters.Add(prmMaxConcurrenceNumber);
                     }



                    

                    if (obj.CurrentDate != DateTime.Now)
                    {
                        DbParameter prmCurrentDate = con.createParameter();
                        prmCurrentDate.ParameterName = "@CurrentDate";
                        prmCurrentDate.DbType =DbType.DateTime;
                        if (obj.CurrentDate == null)
                        {
                            prmCurrentDate.Value = DBNull.Value;
                        }
                        else
                        {
                            prmCurrentDate.Value = obj.CurrentDate;
                        }
                        strWhere += " [CurrentDate]=@CurrentDate OR ";
                        lstParameters.Add(prmCurrentDate);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("OR"));

                    

            

            List<MaxVisitsDate> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<MaxVisitsDate> SearchOrLike(MaxVisitsDate obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<MaxVisitsDate> lstRet = SearchOrLike(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                
        


       
        



    }
}











            